home *** CD-ROM | disk | FTP | other *** search
- /* fx. Send a command to SYSOP via AREXX and store the resulting output
- into a file.
- */
- #include "rexxhostbase.h"
- #include <stdio.h>
-
- struct RexxHostBase *RexxHostBase;
-
- struct RexxHost *rexx_host;
- long rexxbit = 0L;
- char *portname = "test-rexx";
- /* Try to open the rexxhost.library. */
- open_rexx()
- {
- if(!(RexxHostBase = (struct RexxHostBase *)
- OpenLibrary((UBYTE *)REXXHOSTNAME,(long)REXXHOSTMINIMUM))) {
- printf("couldn't open rexxhost library.\n");
- return(1);
- }
-
- /* set up a public port for rexx to talk to us later */
- if(!(rexx_host = CreateRexxHost((STRPTR)portname))) {
- printf("Can't set up public rexx port for port %c\n",portname);
- CloseLibrary((struct Library *)RexxHostBase);
- return(1);
- }
- rexxbit = (1L << rexx_host->rh_Port.mp_SigBit);
- return(0);
- }
- close_rexx()
- {
- struct RexxMsg *rexxmessage; /* incoming rexx messages */
- STRPTR Arg;
-
- /* Drain any messages for us */
- while(rexxmessage = GetRexxMsg(rexx_host,0L)) {
- if(Arg = GetRexxCommand(rexxmessage)) {
- ReplyRexxCommand(rexxmessage,0L,0L,0L);
- }
- else {
- FreeRexxCommand(rexxmessage);
- }
- }
- if(rexx_host)
- rexx_host = DeleteRexxHost(rexx_host);
-
- if(RexxHostBase)
- CloseLibrary((struct Library *)RexxHostBase);
- }
- char cmdstr[100];
- FILE *fdo;
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct RexxMsg *rexxmessage; /* incoming rexx messages */
- STRPTR Arg;
-
- if(argc < 3) {
- printf("Missing argument(s). Send a message to SYSOP via AREXX\n");
- printf("fx filename C-BBS command\n");
- exit(10);
- }
- if(open_rexx()) {
- printf("Can't open rexxhostlib\n");
- exit(10);
- }
- if((fdo = fopen(argv[1],"w")) == NULL) {
- printf("Can't open %s\n",argv[1]);
- exit(10);
- }
- if(SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)"GO test-rexx",0L)) {
- printf("SendRexxMsg - GO failed");
- fclose(fdo);
- exit(10);
- }
- /* Remove the first SYSOP> prompt */
- Wait(rexxbit);
- rexxmessage = GetRexxMsg(rexx_host,0L);
- ReplyRexxCommand(rexxmessage,0L,0L,0L);
- /* Now put together the command and send it to SYSOP */
- argc--;
- argv++;
- while(1) {
- strcat(cmdstr,argv[1]);
- argc--;
- argv++;
- if(argc == 0)break;
- strcat(cmdstr," ");
- }
- if(SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)cmdstr,0L)) {
- printf("SendRexxMsg - command failed");
- fclose(fdo);
- exit(10);
- }
- while(1) {
- Wait(rexxbit);
- while(rexxmessage = GetRexxMsg(rexx_host,0L)) {
- if(Arg = GetRexxCommand(rexxmessage)) {
- if(!strncmp((char *)Arg,"SYSOP>",6)) {
- ReplyRexxCommand(rexxmessage,0L,0L,0L);
- goto done;
- }
- fprintf(fdo,"%s\n",Arg);
- ReplyRexxCommand(rexxmessage,0L,0L,0L);
- }
- else {
- FreeRexxCommand(rexxmessage);
- }
- }
- }
- done:
- fclose(fdo);
- SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)"b",0L);
- close_rexx();
- }
-